package com.qfedu.fmmall.service.config;


import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : yanBin
 * @date :2022/1/10 10:00
 */
@Configuration
public class RedissonConfig {

     //普通配置redisson
    @Value("${redisson.addr.singleAddr.host}")
    private String host;

    @Value("${redisson.addr.singleAddr.password}")
    private String password;

    @Value("${redisson.addr.singleAddr.database}")
    private Integer database;

    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        config.useSingleServer().setAddress(host).setPassword(password).setDatabase(database);
        return Redisson.create(config);
    }

    /**
     * 主从配置redisson
        @Value("${redisson.addr.singleAddr.masterhost}")
        private String masterhost;

        @Value("${redisson.addr.singleAddr.slavehosts}")
        private String slavehosts;
        @Value("${redisson.addr.singleAddr.password}")
        private String password;

        @Value("${redisson.addr.singleAddr.database}")
        private Integer database;

        @Bean
        public RedissonClient redissonClient(){
            Config config = new Config();
            config.useMasterSlaveServers()
                    .setMasterAddress(masterhost)
                    .addSlaveAddress(slavehosts.split("[,]"))
                    .setPassword(password)
                    .setDatabase(database)
                    .setMasterConnectionPoolSize(10000)
                    .setSlaveConnectionPoolSize(10000);
            return Redisson.create(config);
    }

     */

    /**
     * 集群配置redisson
          @Value("${redisson.addr.cluster.hosts}") private String hosts;

          @Value("${redisson.addr.cluster.password}") private String password;

          @Bean public RedissonClient redissonClient(){
          Config config = new Config();
          config.useClusterServers()
          .addNodeAddress(hosts.split("[,]"))
          .setPassword(password).setScanInterval(2000)
          .setMasterConnectionPoolSize(10000)
          .setSlaveConnectionPoolSize(10000);
          return Redisson.create(config);
          }
     */

}
